const { query } = require('express')
const db = require('../dataBase/db')

const getUserlist = () => {
    let sql = 'select * from qqphotos'
    return new Promise((resolve, reject) => {
        db.query(sql, (err, data) => {
            if (err) {
                reject(err)
            }
            resolve(data)
        })

    })
}

//注册新用户
const addUser = (params) => {
    let sql = 'INSERT INTO `qqphotos`(`name`, `password`) VALUES (?, ?)'
    return new Promise((resolve, reject) => {
        db.query(sql, [params.name, params.password],(err, data) => {
    if (err) {
        reject(err)
    }
    resolve(data)
})

    })
}


//查询用户
const getUserbyNameAndPassword = (name, password) => {
    let sql = "SELECT * FROM qqphotos where name=? and password=?";
    return new Promise((resolve, reject) => {
        db.query(sql, [name, password], (err, data) => {
            if (err) {
                reject(err);
            }
            resolve(data);
        });
    });
};

module.exports = {
    getUserlist,
    addUser,
    getUserbyNameAndPassword,
}